package top.hidoctor.auscultation.feature.fragment.other;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.adapter.SampleAdpater;
import top.hidoctor.auscultation.base.BaseFragment;
import top.hidoctor.auscultation.bean.PatientBean;
import top.hidoctor.auscultation.widget.Player;

public class PatientYbFragment extends BaseFragment {
    TabLayout tabLayout;
    RecyclerView recycler;
    private PatientBean info;
    private SampleAdpater adapter;
    private List<PatientBean.ScreeningDtoListBean> screeningDtoList;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_content, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        info = (PatientBean) getArguments().getSerializable("info");
        initView();
        initEvent();
    }

    private void initView() {
        recycler = getActivity().findViewById(R.id.recycler);

    }

    private void initEvent() {
        if (info != null) {
            screeningDtoList = info.getScreeningDtoList();
        }
        LinearLayoutManager mManager = new LinearLayoutManager(getContext());
        recycler.setLayoutManager(mManager);
        recycler.setAdapter(adapter = new SampleAdpater(R.layout.item_yangben_renwubao, screeningDtoList));
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_empty_list, (ViewGroup) recycler.getParent(), false);
        adapter.setEmptyView(view);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Player currentPlayer = adapter.getCurrentPlayer();
        if (currentPlayer != null) {
            currentPlayer.stop();
        }
    }

}
